package com.jiyun.controller;

import com.alibaba.dashscope.aigc.conversation.Conversation;
import com.alibaba.dashscope.aigc.conversation.ConversationParam;
import com.alibaba.dashscope.aigc.conversation.ConversationResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.Constants;
import com.alibaba.dashscope.utils.JsonUtils;
import com.jiyun.result.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ai")
public class AiController {
    public String quickStart(String question) throws ApiException, NoApiKeyException, InputRequiredException {
        Conversation conversation = new Conversation();
        // String prompt = "你好";
        ConversationParam param = ConversationParam
                .builder()
                .model(Conversation.Models.QWEN_TURBO)
                .prompt(question)
                .build();
        ConversationResult result = conversation.call(param);
        System.out.println(JsonUtils.toJson(result));
        System.out.println(result.getOutput().getText());
        return result.getOutput().getText();
        //System.out.println("模型回复："+result.getOutput().getText());
    }
    @RequestMapping("/backinfo")
    public Result<String> backinfo(@RequestParam("question") String question) throws  InputRequiredException {
        Constants.apiKey="sk-3a14ce09d6ce423abd0f36e44fc40227";
        try {
            String info = quickStart(question);
            return Result.ok(info);
        } catch (ApiException | NoApiKeyException e) {
            System.out.println(e.getMessage());
        }
        System.exit(0);
        return null;
    }





}
